package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysUserPasswordDAO;
import com.ourteam.system.dao.SysUserPassword;
import com.ourteam.system.dao.SysUserPasswordDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:35
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysUserPasswordDAOJdbcImpl extends AbstractSpringDAO
    implements ISysUserPasswordDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            UserName, Enabled, Password
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.UserName, _DataObjectProperty.Enabled,
            _DataObjectProperty.Password
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { UserName };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {
            UserName
        };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysUserPassword, SysUserPasswordDAOQueryBean> daoHelper;

    public AbstractSysUserPasswordDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysUserPassword, SysUserPasswordDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysUserPassword
         * @throws Exception
         */
    public boolean checkIsUnique(SysUserPassword aSysUserPassword)
        throws Exception {
        if (aSysUserPassword == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysUserPassword.getUserName());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysUserPassword
     * @throws Exception
     */
    public void insert(SysUserPassword aSysUserPassword)
        throws Exception {
        super.doInsert(aSysUserPassword);
    }

    /**
         * Batch Insert Datas
         * @param aSysUserPassword
         * @throws Exception
         */
    public void batchInsert(SysUserPassword[] aSysUserPasswords)
        throws Exception {
        super.doBatchInsert(aSysUserPasswords);
    }

    /**
         * Delete Data
         * @param  final String userName         *
         * @throws Exception
         */
    public void delete(final String userName) throws Exception {
        super.doDeleteById(new Object[] { userName });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysUserPasswordDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysUserPassword aSysUserPassword)
        throws Exception {
        delete(aSysUserPassword.getUserName());
    }

    /**
     * Update Data Selective
     * @param aSysUserPassword
     * @throws Exception
     */
    public void update(SysUserPassword aSysUserPassword)
        throws Exception {
        if (aSysUserPassword.getUserName() == null) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysUserPassword);

        SysUserPassword tempObj = findById(aSysUserPassword.getUserName());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysUserPassword, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysUserPasswords[]
     * @throws Exception
     */
    public void batchUpdate(SysUserPassword[] aSysUserPasswords)
        throws Exception {
        super.doBatchUpdate(aSysUserPasswords);
    }

    /**
         * Update Data By Condictions
         * @param aSysUserPassword
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysUserPassword aSysUserPassword,
        SysUserPasswordDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aSysUserPassword, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysUserPasswordDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(SysUserPassword aSysUserPassword)
        throws Exception {
        if (aSysUserPassword.getEnabled() == null) {
            throw new Exception(
                "The SysUserPassword.enabled value is not allow NULL");
        }

        if (aSysUserPassword.getPassword() == null) {
            throw new Exception(
                "The SysUserPassword.password value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final String userName         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysUserPassword findById(final String userName)
        throws Exception {
        SysUserPasswordDAOQueryBean queryBean = new SysUserPasswordDAOQueryBean();

        SysUserPasswordDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andUserNameEqualTo(userName);

        //queryBean.setDistinct(true);
        SysUserPassword[] SysUserPasswords = query(queryBean);

        if (SysUserPasswords.length == 0) {
            return null;
        } else {
            return SysUserPasswords[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysUserPassword[]
         * @throws Exception
         */
    public SysUserPassword[] query(SysUserPasswordDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcSysUserPasswordRowMapper());

        return (SysUserPassword[]) result.toArray(new SysUserPassword[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        SysUserPasswordDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysUserPasswordDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(SysUserPassword[] aSysUserPasswords,
        SysUserPasswordDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aSysUserPasswords, queryBean);
    }

    public void synchronize(SysUserPassword[] aSysUserPasswords,
        SysUserPasswordDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysUserPassword> callBack)
        throws Exception {
        daoHelper.synchronize(aSysUserPasswords, queryBean, callBack);
    }

    public static class JdbcSysUserPasswordRowMapper implements RowMapper<SysUserPassword> {
        public SysUserPassword mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysUserPassword object = new SysUserPassword();

            int columnIndex = 1;

            int __dataType;

            try {
                Object userName = null;

                userName = resultSet.getObject(columnIndex++);

                object.setUserNameNull(resultSet.getBoolean(columnIndex++));

                if (userName != null) {
                    setBeanValue(object, _DataObjectProperty.UserName, userName);
                }

                Object enabled = null;

                enabled = resultSet.getObject(columnIndex++);

                object.setEnabledNull(resultSet.getBoolean(columnIndex++));

                if (enabled != null) {
                    setBeanValue(object, _DataObjectProperty.Enabled, enabled);
                }

                Object password = null;

                password = resultSet.getObject(columnIndex++);

                object.setPasswordNull(resultSet.getBoolean(columnIndex++));

                if (password != null) {
                    setBeanValue(object, _DataObjectProperty.Password, password);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
